Skip to content

GH-37004: [C++][Python] Fix dropped child data when viewing/casting e… - #50502

Merged
pitrou merged 1 commit into
apache:mainfrom
connorsimms:gh-37004-extension-view-nested-storage
Jul 22, 2026
Merged

GH-37004: [C++][Python] Fix dropped child data when viewing/casting e…#50502
pitrou merged 1 commit into
apache:mainfrom
connorsimms:gh-37004-extension-view-nested-storage

Conversation

@connorsimms

@connorsimms connorsimms commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

table.cast(table.schema) errored or segfaulted when the schema contained a struct with an extension-typed field whose storage is a list.

This cast takes a zero-copy view, and ViewDataImpl::MakeDataView found children using type->fields(), which is never populated for extension types since their structure is in storage_type(). The same issue exists in AccumulateLayouts. The storage's child data gets dropped and leaves an invalid array that downstream code throws/crashes on.

This bug is similar to #37669, except that the fix for #37669 addressed casting to an extension with nested storage but not this particular struct-wrapped view path.

What changes are included in this PR?

  • cpp/src/arrow/array/data.cc - AccumulateLayouts and ViewDataImpl::MakeDataView now recurse into storage_type()->fields() for ExtensionType, instead of the extension type's empty fields().
  • cpp/src/arrow/array/array_view_test.cc
  • python/pyarrow/tests/test_extension_type.py

Are these changes tested?

Yes,

  • cpp/src/arrow/array/array_view_test.cc - Two tests for viewing an extension array with nested storage for fixed-size and variable-size lists.
  • python/pyarrow/tests/test_extension_type.py - A test casting a table / struct containing an extension type with list-based storage to its own schema.
  • Also, all reproducers from the linked issue were checked against this fix, including the segfault case.

Are there any user-facing changes?

No API changes. Operations that previously raised errors or crashed relating to casting/viewing a struct or table with an extension type with nested storage now succeed.

@connorsimms
connorsimms marked this pull request as ready for review July 14, 2026 19:14
@pitrou

pitrou commented Jul 22, 2026

Copy link
Copy Markdown
Member

For the record, I wouldn't call this a critical fix, more of a regular bug, but the boundary can be a bit fuzzy.

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks good to me. Thank you @connorsimms !

@pitrou
pitrou merged commit 450b793 into apache:main Jul 22, 2026
59 of 60 checks passed
@pitrou pitrou removed the awaiting review Awaiting review label Jul 22, 2026
@github-actions github-actions Bot added the awaiting committer review Awaiting committer review label Jul 22, 2026
@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 450b793.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 6 possible false positives for unstable benchmarks that are known to sometimes produce them.

@connorsimms
connorsimms deleted the gh-37004-extension-view-nested-storage branch July 24, 2026 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants